// 封装options数据

import { ref } from "vue";
// 引入echarts
import * as echarts from "echarts";

// 柱状图
export const BarOptions = ref({
    textStyle: {
        color: "#fff"
    },
    legend: {
        show: false
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '0%',
        top: 10,
        containLabel: true
    },
    xAxis: {
        type: 'value',
        boundaryGap: [0, 0.01],
        splitLine: false,
        axisLabel: false

    },
    yAxis: {
        type: 'category',
        data: ['上海', '天津', '重庆', '广东', '广西', '浙江', '江苏', '湖北'],
    },
    series: [
        {
            name: '2011',
            type: 'bar',

            data: [1803, 2348, 2934, 1970, 1314, 6230, 5420, 6762],
            // 宽度
            barWidth: 4,
            // 圆角
            itemStyle: {
                borderRadius: [0, 20, 20, 0],
                // 渐变色
                color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                    { offset: 0, color: '#a51ffa' },
                    { offset: 0.5, color: '#c413cc' },
                    { offset: 1, color: '#fd007c' }
                ])
            },
        },
        {
            name: '2012',
            type: 'bar',
            data: [1925, 2338, 3100, 1594, 5340, 6860, 1341, 3107],
            // 宽度
            barWidth: 4,
            // 圆角
            itemStyle: {
                borderRadius: [0, 20, 20, 0],
                // 渐变色
                color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                    { offset: 0, color: '#00a1fc' },
                    { offset: 0.5, color: '#00b3ec' },
                    { offset: 1, color: '#00cbd2' }
                ])
            },
        },

        {
            name: '2013',
            type: 'bar',
            data: [1925, 2438, 3100, 1594, 3441, 2759, 6750, 5880],
            // 宽度
            barWidth: 4,
            // 圆角
            itemStyle: {
                borderRadius: [0, 20, 20, 0],
                // 渐变色
                color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                    { offset: 0, color: '#6a665e' },
                    { offset: 0.5, color: '#ae9134' },
                    { offset: 1, color: '#fac102' }
                ])
            },
        }

    ]
})


// 定义饼状图
export const PieOptions = ref({
    tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
    },
    toolbox: {
        show: true,
    },
    series: [
        {
            name: '毕业生工作状态',
            type: 'pie',
            radius: [40, 70],
            roseType: 'radius',

            // 字体颜色
            label: {
                color: 'rgba(255, 255, 255, 0.8)'
            },

            data: [
                { value: 47, name: '已就业' },
                { value: 27.05, name: '未就业' },
                { value: 8.60, name: '返回未就业' },
                { value: 8.65, name: '以往未就业' },
                { value: 8.77, name: '返校重听' }
            ]
            ,  // 自定义背景色
            itemStyle: {
                color: (params: any) => {
                    let newColor = ['#00ff7d', '#00a3fe', '#9665eb', '#e2ca72', '#f76160']
                    return newColor[params.dataIndex]
                }
                // 
            },
        }
    ]
})

// 定义地图图形
export const MapOptions = ref({
    title: {
        text: 'Population Density of Hong Kong （2011）',
        subtext: 'Data from Wikipedia',
        sublink:
            'http://zh.wikipedia.org/wiki/%E9%A6%99%E6%B8%AF%E8%A1%8C%E6%94%BF%E5%8D%80%E5%8A%83#cite_note-12'
    },
    tooltip: {
        trigger: 'item',
        formatter: '{b}<br/>{c} (p / km2)'
    },
    toolbox: {
        show: true,
        orient: 'vertical',
        left: 'right',
        top: 'center',
        feature: {
            dataView: { readOnly: false },
            restore: {},
            saveAsImage: {}
        }
    },
    visualMap: {
        min: 800,
        max: 50000,
        text: ['High', 'Low'],
        realtime: false,
        calculable: true,
        inRange: {
            color: ['lightskyblue', 'yellow', 'orangered']
        }
    },
    series: [
        {
            name: '香港18区人口密度',
            type: 'map',
            map: 'HK',
            label: {
                show: true
            },
            data: [
                { name: '中西区', value: 20057.34 },
                { name: '湾仔', value: 15477.48 },
                { name: '东区', value: 31686.1 },
                { name: '南区', value: 6992.6 },
                { name: '油尖旺', value: 44045.49 },
                { name: '深水埗', value: 40689.64 },
                { name: '九龙城', value: 37659.78 },
                { name: '黄大仙', value: 45180.97 },
                { name: '观塘', value: 55204.26 },
                { name: '葵青', value: 21900.9 },
                { name: '荃湾', value: 4918.26 },
                { name: '屯门', value: 5881.84 },
                { name: '元朗', value: 4178.01 },
                { name: '北区', value: 2227.92 },
                { name: '大埔', value: 2180.98 },
                { name: '沙田', value: 9172.94 },
                { name: '西贡', value: 3368 },
                { name: '离岛', value: 806.98 }
            ],
            // 自定义名称映射
            nameMap: {
                'Central and Western': '中西区',
                Eastern: '东区',
                Islands: '离岛',
                'Kowloon City': '九龙城',
                'Kwai Tsing': '葵青',
                'Kwun Tong': '观塘',
                North: '北区',
                'Sai Kung': '西贡',
                'Sha Tin': '沙田',
                'Sham Shui Po': '深水埗',
                Southern: '南区',
                'Tai Po': '大埔',
                'Tsuen Wan': '荃湾',
                'Tuen Mun': '屯门',
                'Wan Chai': '湾仔',
                'Wong Tai Sin': '黄大仙',
                'Yau Tsim Mong': '油尖旺',
                'Yuen Long': '元朗'
            }
        }
    ]
})


// 定义options
const option = {
    legend: {
        textStyle: {
            color: '#dbdbdb'
        },
        icon: 'circle'
    },
    tooltip: {
        trigger: 'axis',
        showContent: true
    },
    grid: { top: '25%', left: 45 },
    xAxis: { type: 'category' },
    series: [

    ]
}
export const lineOption = {
    ...JSON.parse(JSON.stringify(option)),
    yAxis: { gridIndex: 0 },
    dataset: {
        source: [

        ]
    }
};

export const barOption = {
    ...JSON.parse(JSON.stringify(option)),
    grid: { top: '25%', left: 45, },

    yAxis: {
        type: 'value',
    },
    // barWidth
    // series: [
    //     {
    //         barWidth: 10
    //     }
    // ]
};